/*
 * {comment of class}
 *
 * @author (C) <a href="http://www.carfield.com.hk">Carfield Yim </a>, 2004
 */
package hk.com.carfield.content;

import hk.com.carfield.core.Config;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public final class IEFavorites implements Content, Redirector {
	private final Config config;

	private final File file;

	private final String url;

	public IEFavorites(final Config config, final File file) throws IOException {
		super();
		this.config = config;
		this.file = file;
		url = getUrl();
	}

	public String getContent() {
		return url;
	}

	public String getUrl() throws IOException {
		final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
		String temp;
		try {
			temp = "";
			while ((temp = br.readLine()) != null) { // skip first line
													// [InternetShortcut]
				if (temp.indexOf("InternetShortcut") > -1) {
					temp = br.readLine().substring(4);
					break;
				}
				if (temp.indexOf("DEFAULT") > -1) {
					temp = br.readLine().substring(8);
					break;
				}
			}
		} finally {
			br.close();
		}
		return temp;
	}

	public String getThumbnail() {
		// TODO add default icon for difference type... should get through
		// servlet so that one jar is ok
		return null;
	}
	// TODO see if we persist link's meta (from google??)
}